import java.util.*;
import java.io.*;
public class test {
    // 蓝桥杯 社交网络新来的朋友(⭐⭐⭐)
    public class test9 {
        public static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        public static Read in = new Read();
        public static int n;
        public static int[] fx;
        public static void main(String[] args) throws IOException {
            n = in.nextInt();
            int e = in.nextInt();
            fx = new int[n + 1];
            for(int i = 1;i <= n;i++) {
                fx[i] = i;
            }
            while(e-- > 0) {
                int a = in.nextInt();
                int b = in.nextInt();
                setFx(a, b);
            }
            int m = in.nextInt();
            while(m-- > 0) {
                int a = in.nextInt();
                int b = in.nextInt();
                setFx(a, b);
            }
            int root = getFx(1);
            for(int i = 2;i <= n;i++) {
                if(getFx(i) != root) {
                    System.out.println("NO");
                    return;
                }
            }
            System.out.println("YES");
        }
        public static int getFx(int x) {
            if(fx[x] != x) {
                fx[x] = getFx(fx[x]);
            }
            return fx[x];
        }
        public static void setFx(int a,int b) {
            int x1 = getFx(a);
            int x2 = getFx(b);
            if(x1 == x2) {
                return;
            }else {
                fx[x1] = x2;
            }
        }
        // 蓝桥杯 联盟X
        public static ArrayList<Integer>[] lists;
        public static boolean[] count;
        public static int num;
        public static void main(String[] args) throws IOException{
            int n = in.nextInt();
            int m = in.nextInt();
            lists = new ArrayList[n + 1];
            count = new boolean[n + 1];
            for(int i = 1;i <= n;i++) {
                lists[i] = new ArrayList<Integer>();
            }
            while(m-- > 0) {
                int a1 = in.nextInt();
                int a2 = in.nextInt();
                //邻接表链接a1与a2
                if(!lists[a1].contains(a2))
                    lists[a1].add(a2);
                if(!lists[a2].contains(a1))
                    lists[a2].add(a1);
            }
            // 1<->2<->3   4<->5
            // 如果某个村子的指向>=2,代表它处于某个联盟中
            // 相对的,如果某个村子的指向<2,代表它就是某个联盟的开头
            int min = n + 5;
            for(int i = 1;i <= n;i++) {
                //获取这个村子的指向大小
                int len = lists[i].size();
                if(len < 2 && !count[i]) {
                    num = 0;
                    bfs(i);
                    min = Math.min(min, num);
                }
            }
            System.out.println(min);
        }
        public static void bfs(int x) {
            Queue<Integer> queue = new LinkedList<>();
            count[x] = true;
            queue.add(x);
            while(!queue.isEmpty()){
                int a = queue.poll();
                num++;
                for(int h:lists[a]){
                    if(!count[h]){
                        count[h] = true;
                        queue.add(h);
                    }
                }
            }
        }
    }
    class Read {
        StringTokenizer st = new StringTokenizer("");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String next() throws IOException {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }
        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    }
}
